﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Microsoft.FamilyShow"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    x:Class="Microsoft.FamilyShow.PersonInfo"
    xmlns:properties="clr-namespace:Microsoft.FamilyShow.Properties"
    IsVisibleChanged="UserControl_IsVisibleChanged">
    <UserControl.Resources>

        <!-- Converter for displaying the the first name with an apostrophe. -->
        <local:FirstNamePossessiveFormConverter x:Key="FirstNamePossessiveFormConverter"/>

        <local:ImageConverter x:Key="ImageConverter"/>

        <!-- Converter for showing/hiding features based on boolean property -->
        <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>

        <!-- Converter for showing/hiding features based on boolean property -->
        <local:NotBoolToVisibilityConverter x:Key="NotBoolToVisibilityConverter"/>

        <!-- Converter for disabling -->
        <local:NotConverter x:Key="NotConverter"/>

        <Style x:Key="formatTextStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="FontFamily" Value="Palatino Linotype"/>
            <Setter Property="Width" Value="30"/>
            <Setter Property="FontSize" Value ="14"/>
        </Style>

        <Style x:Key="formatImageStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="Width" Value="30" />
            <Setter Property="CommandTarget" Value="{Binding ElementName=StoryRichTextBox}"/>
        </Style>

        <Image x:Key="deleteico" Source="..\Images\Delete.png" Height="16" Width="16" />
        <Image x:Key="primaryico" Source="..\Images\Primary.png" Height="16" Width="16" />
        <Image x:Key="openico" Source="..\Images\AddImage.png" Height="16" Width="16" />

    </UserControl.Resources>

    <Border Margin="10,0,10,10" Style="{DynamicResource BorderStyle}" Background="{DynamicResource BackgroundBrush}">
        <DockPanel>

            <!-- Header Panel-->
            <DockPanel Margin="0,0,10,0" DockPanel.Dock="Top" Height="30">
                <!-- Star -->
                <Path StrokeThickness="1.500000" Stroke="#ffffffff" StrokeMiterLimit="1.000000" Fill="#ff3952a3" Data="F1 M 9.816406,1.694336 L 12.351074,6.830078 L 18.018066,7.654297 L 13.918457,11.654297 L 14.886230,17.299805 L 9.816406,14.630859 L 4.746094,17.299805 L 5.713867,11.654297 L 1.611328,7.654297 L 7.281250,6.830078 L 9.816406,1.694336 Z" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center"/>
                <TextBlock TextTrimming="CharacterEllipsis" MaxWidth="700" MaxHeight="30"  LineStackingStrategy="MaxHeight" Text="{Binding Path=Name, Mode=Default, FallbackValue=Name}" Style="{DynamicResource HeaderStyle}" FontWeight="Bold" Margin="5,0,0,0" VerticalAlignment="Center" Foreground="{DynamicResource HeaderFontColor}"/>
                <Button Margin="0,0,3,0" Width="Auto" MinWidth="40" Content="{x:Static properties:Resources.Back}" Click="CloseButton_Click" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" DockPanel.Dock="Right" Height="15" x:Name="CloseButton" IsCancel="True" IsDefault="True" FontSize="10"/>
             </DockPanel>

            <Border CornerRadius="0,0,10,10" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0,1,0,0" Background="{DynamicResource PersonInfoBackgroundBrush}">
                <Grid DockPanel.Dock="Top">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="0.48*"/>
                        <ColumnDefinition Width="0.52*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <!-- Photos Info-->

                    <Border Margin="10,10,5,5" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1,1,1,1" CornerRadius="10,10,0,0">

                        <StackPanel>
                            <Menu VerticalAlignment="Bottom" Margin="10,5,0,0" Style="{DynamicResource MenuStyle}">
                                <MenuItem Header="{x:Static properties:Resources.Add}" Style="{DynamicResource MenuItemStyle}">
                                    <MenuItem Header="{x:Static properties:Resources.AddNewImage}" Click="Add_Click" IsCheckable="False" IsChecked="False" Icon="{StaticResource openico}"/>
                                    <MenuItem Header="{x:Static properties:Resources.LinkExistingImage}" Click="Link_Click" IsCheckable="False" IsChecked="False"/>
                                </MenuItem>
                                <MenuItem Header="{x:Static properties:Resources.Edit}" Style="{DynamicResource MenuItemStyle}" Visibility="{Binding Path=HasPhoto, Converter={StaticResource BoolToVisibilityConverter}, Mode=Default}">
                                    <MenuItem Visibility="{Binding Path=IsLocked, Converter={StaticResource NotBoolToVisibilityConverter}, Mode=Default}" x:Name="Primary" Header="{x:Static properties:Resources.SetAsPrimary}" Click="PrimaryButton_Click" IsCheckable="False" IsChecked="False" Icon="{StaticResource primaryico}"/>
                                    <MenuItem Visibility="{Binding Path=IsLocked, Converter={StaticResource NotBoolToVisibilityConverter}, Mode=Default}" x:Name="NoPrimary" Header="{x:Static properties:Resources.NoPrimary}" Click="NoPrimaryButton_Click" IsCheckable="False" IsChecked="False"/>
                                    <MenuItem Visibility="{Binding Path=IsLocked, Converter={StaticResource NotBoolToVisibilityConverter}, Mode=Default}" x:Name="Delete" Header="{x:Static properties:Resources.Delete}" Click="DeletePhotoButton_Click" IsCheckable="False" IsChecked="False" Icon="{StaticResource deleteico}"/>
                                </MenuItem>
                                <MenuItem Header="{x:Static properties:Resources.View}" Style="{DynamicResource MenuItemStyle}" Click="OpenPhotoButton_Click" Visibility="{Binding Path=HasPhoto, Converter={StaticResource BoolToVisibilityConverter}, Mode=Default}"/>
                            </Menu>

                            <Image x:Name="DisplayPhoto" Margin="10,10,10,10" Stretch="Uniform" MaxHeight="280" Height="280"/>
                            
                            <TextBlock Visibility="{Binding Path=HasPhoto, Converter={StaticResource BoolToVisibilityConverter}, Mode=Default}" HorizontalAlignment="Left" Height="15" MinWidth="100" MaxWidth="415" MaxHeight="20" x:Name="CaptionTextBlock" Margin="10,0,0,0" Foreground="{DynamicResource FontColor}" FontSize="11" FontStyle="Italic" TextTrimming="CharacterEllipsis"/>
                            
              <StackPanel Orientation="Horizontal" x:Name="TagsStackPanel">
                <Label Content="{x:Static properties:Resources.TagsColon}" FontSize="11" VerticalAlignment="Stretch" Foreground="{DynamicResource FontColor}" HorizontalAlignment="Stretch" Margin="5,0,0,0"/>
                <ListBox MaxWidth="300" MaxHeight ="25" Height="25" x:Name="TagsListBox" Background="{x:Null}" BorderBrush="{x:Null}" Style="{DynamicResource TagsListStyle}" ItemTemplate="{DynamicResource TagsItemTemplate}" FontSize="11" Margin="0,3,0,0"  />
              </StackPanel>
            </StackPanel>

                    </Border>

                    <!-- Photos List Box-->

                    <Border Grid.Row="1" Margin="10,0,5,10" CornerRadius="0,0,10,10" BorderThickness="1,1,1,1" Padding="10,5,10,5" BorderBrush="{DynamicResource BorderBrush}">
                        <Grid>

                            <TextBlock  Visibility="{Binding Path=HasPhoto, Converter={StaticResource NotBoolToVisibilityConverter}, Mode=Default}" HorizontalAlignment="Left" Foreground="{DynamicResource FontColor}" FontSize="10"><Run Text="{x:Static properties:Resources.DropPhotosIntoThisBox}"/></TextBlock>
                            <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">

                                <ListBox KeyDown="PhotosListBox_KeyDown" AllowDrop="True"  ScrollViewer.CanContentScroll="True" x:Name="PhotosListBox" Background="{x:Null}" ItemsSource="{Binding Path=Photos, Mode=Default}" IsSynchronizedWithCurrentItem="True" Drop="PhotosListBox_Drop" Style="{DynamicResource PhotosListStyle}" ItemContainerStyle="{DynamicResource PhotosListItemStyle}" SelectionChanged="PhotosListBox_SelectionChanged" Margin="0,0,0,0"/>
                            </ScrollViewer>
                        </Grid>
                    </Border>


                    <!-- Story View -->
                    <Border x:Name="StoryViewBorder" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1,1,1,1" CornerRadius="10,10,10,10" Grid.Column="1" Grid.RowSpan="2" Margin="5,10,10,10">
                        <Grid Focusable="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="35"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <DockPanel Margin="10,10,0,0">
                                <TextBlock TextTrimming="CharacterEllipsis" MaxWidth="235" MaxHeight="30" LineStackingStrategy="MaxHeight" Text="{Binding Path=FirstName, Converter={StaticResource FirstNamePossessiveFormConverter}, Mode=Default, FallbackValue=Name}" TextWrapping="Wrap" Style="{DynamicResource HeaderStyle}" FontSize="18" FontWeight="Bold" Margin="5,0,0,0"/>
                                <TextBlock TextWrapping="Wrap" Style="{DynamicResource HeaderStyle}" FontSize="18" FontWeight="Bold" Margin="0,0,0,0"><Run Text="{x:Static properties:Resources.Story}"/></TextBlock>
                                <Button Width="Auto" MinWidth="65" x:Name="EditStoryButton" Visibility="{Binding Path=IsLocked, Converter={StaticResource NotBoolToVisibilityConverter}, Mode=Default}" Content="{x:Static properties:Resources.Edit}" Click="EditStoryButton_Click" HorizontalAlignment="Right" Margin="0,2,10,0" DockPanel.Dock="Right" VerticalAlignment="Top" Height="15" FontSize="10"/>
				                <Button Width="Auto" MinWidth="65" x:Name="PrintStoryButton" Content="{x:Static properties:Resources.PrintMenu}" Visibility="{Binding Path=IsPrivate, Converter={StaticResource NotBoolToVisibilityConverter}, Mode=Default}" Click="PrintStoryButton_Click" HorizontalAlignment="Right" Margin="0,2,10,0" DockPanel.Dock="Right" VerticalAlignment="Top" Height="15" FontSize="10" Style="{DynamicResource RedButtonStyle}"/>
                              </DockPanel>


                            <FlowDocumentReader Foreground="{DynamicResource FontColor}" HorizontalAlignment="Stretch" x:Name="StoryViewer" VerticalAlignment="Stretch" Grid.Row="1" Margin="0,0,10,0" MinZoom="50" Zoom="100" IsFindEnabled="False" IsPrintEnabled="{Binding Path=IsPrivate, Converter={StaticResource NotConverter}, Mode=Default}" IsTwoPageViewEnabled="False" MaxZoom="150" Background="#00FFFFFF" ForceCursor="False" Opacity="1">
                                <FlowDocument IsOptimalParagraphEnabled="true" IsHyphenationEnabled="true" Foreground="{DynamicResource FlowDocumentFontColor}"/>
                            </FlowDocumentReader>


                        </Grid>
                    </Border>

                    <!-- Story Edit -->
                    <Border x:Name="StoryEditBorder" Grid.Column="1" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1,1,1,1" CornerRadius="10,10,10,10" Grid.RowSpan="2" Margin="5,10,10,10">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="35"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <DockPanel Margin="10,10,0,0">
                                <TextBlock  TextTrimming="CharacterEllipsis" MaxWidth="235" MaxHeight="30"  LineStackingStrategy="MaxHeight" Text="{Binding Path=FirstName, Converter={StaticResource FirstNamePossessiveFormConverter}, Mode=Default, FallbackValue=Name}" TextWrapping="Wrap" Style="{DynamicResource HeaderStyle}" FontSize="18" FontWeight="Bold" Margin="5,0,0,0"/>
                                <TextBlock TextWrapping="Wrap" Style="{DynamicResource HeaderStyle}" FontSize="18" FontWeight="Bold" Margin="0,0,0,0"><Run Text="{x:Static properties:Resources.Story}"/></TextBlock>
                                <Button Width="Auto" MinWidth="65" HorizontalAlignment="Right" Margin="0,2,10,0" x:Name="CancelStoryButton" Content="{x:Static properties:Resources.Cancel}" DockPanel.Dock="Right" IsCancel="True" Click="CancelStoryButton_Click" FontSize="10" Height="15" VerticalAlignment="Top"/>
                                <Button Width="Auto" MinWidth="65" x:Name="SaveStoryButton" Content="{x:Static properties:Resources.Save}" HorizontalAlignment="Right" Margin="0,2,10,0" DockPanel.Dock="Right" IsDefault="True" Click="SaveStoryButton_Click" FontSize="10" Height="15" VerticalAlignment="Top" Style="{DynamicResource RedButtonStyle}" />
                            </DockPanel>
                            <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1" Margin="10,0,10,10">

                                <!-- This tool bar contains all the editing buttons. -->
                                <ToolBar Height="30" DockPanel.Dock="Top" Visibility="Visible">

                                    <ToggleButton Name="BoldButton" Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleBold" ToolTip="{x:Static properties:Resources.Bold}">
                                        <TextBlock FontWeight="Bold">B</TextBlock>
                                    </ToggleButton>
                                    <ToggleButton Name="ItalicButton" Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleItalic" ToolTip="{x:Static properties:Resources.Italic}">
                                        <TextBlock FontStyle="Italic" FontWeight="Bold">I</TextBlock>
                                    </ToggleButton>
                                    <ToggleButton Name="UnderlineButton" Style="{StaticResource formatTextStyle}" Command="EditingCommands.ToggleUnderline" ToolTip="{x:Static properties:Resources.Underline}">
                                        <TextBlock TextDecorations="Underline" FontWeight="Bold">U</TextBlock>
                                    </ToggleButton>

                                    <ComboBox Name="FontsComboBox" Width="150" SelectionChanged="FontsComboBox_SelectionChanged" />

                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseFontSize" ToolTip="{x:Static properties:Resources.GrowFont}">
                                        <Image Source="..\Images\CharacterGrowFont.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseFontSize" ToolTip="{x:Static properties:Resources.ShrinkFont}">
                                        <Image Source="..\Images\CharacterShrinkFont.png"/>
                                    </Button>
                                    
                                    <Separator/>
                                    <ToggleButton Name="BulletsButton" Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleBullets" ToolTip="{x:Static properties:Resources.Bullets}">
                                        <Image Source="..\Images\ListBullets.png"/>
                                    </ToggleButton>
                                    <ToggleButton Name="NumberingButton" Style="{StaticResource formatImageStyle}" Command="EditingCommands.ToggleNumbering" ToolTip="{x:Static properties:Resources.Numbering}">
                                        <Image Source="..\Images\ListNumbering.png"/>
                                    </ToggleButton>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.DecreaseIndentation" ToolTip="{x:Static properties:Resources.DecreaseIndentation}">
                                        <Image Source="..\Images\ParagraphDecreaseIndentation.png"/>
                                    </Button>
                                    <Button Style="{StaticResource formatImageStyle}" Command="EditingCommands.IncreaseIndentation" ToolTip="{x:Static properties:Resources.IncreaseIndentation}">
                                        <Image Source="..\Images\ParagraphIncreaseIndentation.png"/>
                                    </Button>
                                    <Separator/>

                                    <ToggleButton Name="AlignLeftButton" Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignLeft" ToolTip="{x:Static properties:Resources.AlignLeft}">
                                        <Image Source="..\Images\ParagraphLeftJustify.png"/>
                                    </ToggleButton>
                                    <ToggleButton Name="AlignCenterButton" Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignCenter" ToolTip="{x:Static properties:Resources.AlignCenter}">
                                        <Image Source="..\Images\ParagraphCenterJustify.png"/>
                                    </ToggleButton>
                                    <ToggleButton Name="AlignRightButton" Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignRight" ToolTip="{x:Static properties:Resources.AlignRight}">
                                        <Image Source="..\Images\ParagraphRightJustify.png"/>
                                    </ToggleButton>
                                    <ToggleButton Name="AlignFullButton" Style="{StaticResource formatImageStyle}" Command="EditingCommands.AlignJustify" ToolTip="{x:Static properties:Resources.AlignJustify}">
                                        <Image Source="..\Images\ParagraphFullJustify.png"/>
                                    </ToggleButton>
                                    
                                    
                                </ToolBar>
                                <Border BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource LightBrush}" BorderThickness="1,1,1,1">
                                    <RichTextBox x:Name="StoryRichTextBox" Grid.RowSpan="1" AcceptsTab="True" SpellCheck.IsEnabled="true" 
                    SelectionChanged="StoryRichTextBox_SelectionChanged" TextChanged="StoryRichTextBox_TextChanged" Focusable="True" Visibility="Visible" />
                                </Border>
                            </DockPanel>
                        </Grid>
                    </Border>

                </Grid>
            </Border>

        </DockPanel>
    </Border>
</UserControl>
